<?xml version="1.0" encoding="utf-8" ?>
<xs:schema  attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
  <!--<xs:element name="bookstore" type="bookstoreType" />
	<xs:element name="comment" type="xs:string" />
	<xs:element name="author" type="authorName"/>-->
  <!--name="QueryOptimalizationTester"-->
  <xs:annotation>
    <xs:appinfo>Query Optimalization Tester</xs:appinfo>
    <xs:documentation xml:lang="en">
      Version 1.0: Test
    </xs:documentation>
  </xs:annotation>

  <xs:element name="QOT">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="settings">
          <xs:complexType>
            <xs:sequence>
              <xs:element name="observeddirectories">
                <xs:complexType>
                  <xs:sequence minOccurs="0">
                    <xs:element maxOccurs="unbounded"  name="directory">
                      <xs:complexType>
                        <xs:attribute name="dir" type="xs:string"/>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="servers">
                <xs:complexType>
                  <xs:sequence minOccurs="0">
                    <xs:element maxOccurs="unbounded"  name="server">
                      <xs:complexType>
                        <xs:sequence minOccurs="0">
                          <xs:element name="databases">
                            <xs:complexType>
                              <xs:sequence>
                                <xs:element maxOccurs="unbounded" name="database">
                                  <xs:complexType>
                                    <xs:sequence minOccurs="0">
                                      <xs:element name="tables">
                                        <xs:complexType>
                                          <xs:sequence>
                                            <xs:element maxOccurs="unbounded" name="table">
                                              <xs:complexType>
                                                <xs:attribute name="id" type="xs:int"/>
                                                <xs:attribute name="name" type="xs:string"/>
                                                <xs:attribute name="schema" type="xs:string"/>
                                                <xs:attribute name="tablechecked" type="Bool"/>
                                                <xs:attribute name="createdate" type="Date"/>
                                                <xs:attribute name="count" type="xs:int"/>
                                                <xs:attribute name="mindate" type="DateTime"/>
                                                <xs:attribute name="maxdate" type="DateTime"/>
                                                <xs:attribute name="refreshdate" type="DateTime"/>
                                                <xs:attribute name="wasrefreshed" type="xs:string"/>
                                              </xs:complexType>
                                            </xs:element>
                                          </xs:sequence>
                                        </xs:complexType>
                                      </xs:element>
                                    </xs:sequence>
                                    <xs:attribute name="id" type="xs:int"/>
                                    <xs:attribute name="name" type="xs:string"/>
                                    <xs:attribute name="databasechecked" type="Bool" use="required"/>
                                  </xs:complexType>
                                </xs:element>
                              </xs:sequence>
                            </xs:complexType>
                          </xs:element>
                        </xs:sequence>
                        <xs:attribute name="id" type="xs:int" use="optional"/>
                        <xs:attribute name="serverchecked" type="Bool" use="required"/>
                        <xs:attribute name="serveruseinthisproject" type="Bool" use="required"/>
                        <xs:attribute name="SSPI" type="Bool" use="required"/>
                        <xs:attribute name="login" type="xs:string" use="optional"/>
                        <xs:attribute name="password" type="xs:string" use="optional"/>
                        <xs:attribute name="address" type="Address" use="required"/>
                        <xs:attribute name="Type" type="xs:string" use="optional"/>
                      </xs:complexType>
                    </xs:element>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
              <xs:element name="procedures">
                <xs:complexType>
                  <xs:sequence>
                    <xs:sequence minOccurs="0">
                        <xs:element maxOccurs="unbounded" name="procedure">
                          <xs:complexType>
                            <xs:sequence>
                              <xs:element name="ProcedureFromFile">
                                <xs:complexType>
                                  <xs:sequence>
                                    <xs:element name="Version">
                                      <xs:complexType>
                                        <xs:attribute name="Version" type="xs:string" use="required" />
                                        <xs:attribute name="User" type="xs:string" use="required" />
                                        <xs:attribute name="Project" type="xs:string" use="required" />
                                        <xs:attribute name="Date" type="Date" use="required" />
                                        <xs:attribute name="Comment" type="xs:string" use="required" />
                                      </xs:complexType>
                                    </xs:element>
                                  </xs:sequence>
                                  <xs:attribute name="Name" type="xs:string" use="required" />
                                  <xs:attribute name="Creationtime" type="xs:dateTime" use="required" />
                                  <xs:attribute name="Modifiedtime" type="xs:dateTime" use="required" />
                                  <xs:attribute name="ActionInProcedure" type="xs:string" use="required" />
                                  <xs:attribute name="Type" type="xs:string" use="required" />
                                  <xs:attribute name="Version" type="xs:string" use="required" />
                                  <xs:attribute name="Hash" type="xs:string" use="required" />
                                  <xs:attribute name="Location" type="xs:string" use="required" />
                                  <xs:attribute name="Owner" type="xs:string" use="optional" />
                                </xs:complexType>
                              </xs:element>
                              <xs:element minOccurs="0" name="ProcedureFromDatabase">
                                <xs:complexType>
                                  <xs:sequence>
                                    <xs:element name="Version">
                                      <xs:complexType>
                                        <xs:attribute name="Version" type="xs:string" use="required" />
                                        <xs:attribute name="User" type="xs:string" use="required" />
                                        <xs:attribute name="Project" type="xs:string" use="required" />
                                        <xs:attribute name="Date" type="Date" use="required" />
                                        <xs:attribute name="Comment" type="xs:string" use="required" />
                                      </xs:complexType>
                                    </xs:element>
                                  </xs:sequence>
                                  <xs:attribute name="Name" type="xs:string" use="required" />
                                  <xs:attribute name="Creationtime" type="xs:dateTime" use="required" />
                                  <xs:attribute name="Modifiedtime" type="xs:dateTime" use="required" />
                                  <xs:attribute name="ActionInProcedure" type="xs:string" use="required" />
                                  <xs:attribute name="Type" type="xs:string" use="required" />
                                  <xs:attribute name="Version" type="xs:string" use="required" />
                                  <xs:attribute name="Hash" type="xs:string" use="required" />
                                  <xs:attribute name="Location" type="xs:string" use="required" />
                                  <xs:attribute name="DataBase" type="xs:string" use="required" />
                                  <xs:attribute name="Owner" type="xs:string" use="required" />
                                  <xs:attribute name="Server" type="xs:string" use="required" />
                                </xs:complexType>
                              </xs:element>
                            </xs:sequence>
                            <xs:attribute name="id" type="xs:unsignedByte" use="required" />
                            <xs:attribute name="name" type="xs:string" use="required" />
                            <xs:attribute name="looking" type="Bool" use="required" />
                            <xs:attribute name="isopen" type="Bool" use="required" />
                            <xs:attribute name="saved" type="Bool" use="required" />
                            <xs:attribute name="found" type="xs:integer" use="required" />
                            <xs:attribute name="starttime" type="DateTime" use="required" />
                            <xs:attribute name="endtime" type="DateTime" use="required" />
                          </xs:complexType>
                        </xs:element>
                    </xs:sequence>
                  </xs:sequence>
                </xs:complexType>
              </xs:element>
            </xs:sequence>
            <xs:attribute name="queries" type="xs:int" use="required"/>
            <xs:attribute name="projectname" type="xs:string" use="required"/>
            <xs:attribute name="projectlocation" type="xs:string" use="required"/>
            <xs:attribute name="projectoldprocedurelocation" type="xs:string" use="optional"/>
            <xs:attribute name="projectnewprocedurelocation" type="xs:string" use="optional"/>
          </xs:complexType>
        </xs:element>
      </xs:sequence>
      <xs:attribute name="version" type="xs:int"/>
    </xs:complexType>
  </xs:element>


  <xs:simpleType name ="Address">
    <xs:restriction base="xs:string">
      <xs:pattern value="([0-9]{1,3}-[0-9]{1,3}-[0-9]{1-3}-[0-9]{1,3}(//{1}.*){0-1})|(.+(\..*){0,1})"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name ="Bool">
    <xs:restriction base="xs:string">
      <xs:enumeration value="True"/>
      <xs:enumeration value="False"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="Date">
    <xs:restriction base="xs:string">
      <xs:pattern value="[0-9]{4}-[0-9]{2}-[0-9]{2}"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="DateTime">
    <xs:restriction base="xs:string">
      <xs:pattern value="([0-9]{4})-(0?[1-9]|1[0-2])-(([0-2][0-9])|(3[01]))\s([01][0-9]|2[0-3])(:[0-5]\d){0,2}(\.[0-9]{3}){0,1}"/>
    </xs:restriction>
  </xs:simpleType>

</xs:schema>
